package com.jerry.chat.service;

import com.jerry.chat.dao.UserMapper;
import com.jerry.chat.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public User login(User user) {
        var u = userMapper.getForLogin(user.getId(), user.getPassword());
        if (u == null) {
            return null;
        }

        userMapper.updateCid(user.getId(), user.getCid());
        u.setCid(user.getCid());
        return u;
    }

    @Override
    public List<User> getFriendList(String id) {
        return userMapper.getFriendList(id);
    }

    @Override
    public void updateFacepath(User user) {
        userMapper.updateFacepath(user);
    }
}
